package de.wittje.games.mlpbd.controller;

import java.io.InputStream;

import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;

public class SoundController {

	private BackgroundMusic bgm;

	/**
	 * Plays a Sound with the given name from the folder data/sounds/
	 * 
	 * @param sound
	 *            the unique indicator of the sound
	 */
	public void playSound(String sound) {

		try {
			InputStream in = this.getClass().getResourceAsStream(
					"/de/wittje/games/mlpbd/data/sounds/" + sound + ".mp3");

			Player p;

			p = new Player(in);
			p.play();
		} catch (JavaLayerException e) {
			e.printStackTrace();
		}

	}

	public void playMusic(String track) {
		if (bgm != null) {
			bgm.stop();
		}
		bgm = new BackgroundMusic(track);
		new Thread(bgm).run();

	}

}
